package com.lanhai.zhonglai;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.lanhai.zhonglai.hc.HCQueueThread;
import com.lanhai.zhonglai.interfaces.IControlArea;
import com.lanhai.zhonglai.interfaces.IStation; 
import com.lanhai.zhonglai.interfaces.IDot;
import com.lanhai.zhonglai.interfaces.IPower;
import com.lanhai.zhonglai.interfaces.IRoad; 
import com.lanhai.zhonglai.listener.AgvListener;
import com.lanhai.zhonglai.listener.StationListener;
import com.lanhai.zhonglai.listener.HackListener;
import com.lanhai.zhonglai.report.AgvStateThread;
import com.lanhai.zhonglai.report.StationStateThread;
import com.lanhai.zhonglai.third.KSHeartThread;
  

/**
 * 各种侦听管理
 * @author zhengwei
 *
 */
@Component
public class ListenerManager {
	@Autowired
	AgvListener agvListener;
	
	@Autowired
	StationListener stationListener;

	@Autowired
	StationListener popaldListener; 

	@Autowired
	StationListener hcListener; 
	
	
	@Autowired
	StationListener ksListener; 

	@Autowired
	StationListener jsListener; 
	
	@Autowired
	StationListener aldListener; 
	 
	
	@Autowired
	StationListener swListener; 
	
	@Autowired
	StationListener cbListener; 
	
	@Autowired
	HackListener hackListener;
	
	@Autowired
	AgvStateThread agvStateListener;
	
	@Autowired
	StationStateThread stationStateListener;
	
	MsgCore msgCore;
	
	
	@Autowired
	IRoad iRoad;
	
	@Autowired
	IControlArea iControlArea;
	
	@Autowired
	IDot iDot;
	
	@Autowired
	IStation iStation;
	
	@Autowired
	IPower iPower;
	 
	 @Autowired
	    KSHeartThread heart;
	
	 @Autowired
	 HCQueueThread hcThread;
	 
	
	public void start() { 
		// **************** 初始化数据库
		iRoad.init();
		iControlArea.init();
		iDot.init();
		iStation.init();
		iPower.init();

		// **************** 初始化各线程
		agvListener.Start(5000);
		stationListener.Start(9700);
		popaldListener.Start(9800); // POPAID专用
		jsListener.Start(9500); // 江松镀膜专用
		ksListener.Start(9501); // 扩散

		cbListener.Start(9100); // 发料机
		
		aldListener.Start(9502); // ald专用
		swListener.Start(9527); // 丝网专用
		hcListener.Start(9888);  // 缓存机专用
		hackListener.Start();

		agvStateListener.Start(1);
		stationStateListener.Start(1);
		msgCore = new MsgCore("10.11.35.240");
		msgCore.Start();
		heart.Start();
		
		hcThread.Start( );
	}
	
	public void stop() {
		agvListener.Stop();
		stationListener.Stop(); 
		hackListener.Stop();
	    agvStateListener.Stop();
	    msgCore.Stop(); 
	    heart.Stop();
	    aldListener.Stop();
	    ksListener.Stop();
	    popaldListener.Stop();
	    stationStateListener.Stop();
	    swListener.Stop();
	    cbListener.Stop();
	    hcThread.Stop();
	}

	@Override
	protected void finalize() throws Throwable {
		stop(); 
	}
	
	
}
